Dashboard Temp Share Shortlinks Frames API

HTMLify

Implement Upper Bound.cpp
Views: 1 | Author: cody
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
int upperBound(vector<int> &arr, int x, int n){
	// Write your code here.
	int start = 0;
	int end = n-1;

	int mid = start +(end - start) /2;
	int ans = n;
	while(start<=end){
		
		if(arr[mid]> x){
			ans = mid;
			end = mid - 1;
		}
		else{
			start = mid + 1;
		}
		mid = start + (end - start) /2;
	}
	return ans;	
}